using System.Linq;

namespace eBookDirectory.Infrastructure.Repository
{
    public abstract class RepositoryLocatorBase : IRepositoryLocator
    {
        public TEntity Save<TEntity>(TEntity instance)
        {
            IRepository<TEntity> repository = GetRepository<TEntity>();
            return repository.Save(instance);
        }

        public void Update<TEntity>(TEntity instance)
        {
            IRepository<TEntity> repository = GetRepository<TEntity>();
            repository.Update(instance);
        }

        public void Remove<TEntity>(TEntity instance)
        {
            IRepository<TEntity> repository = GetRepository<TEntity>();
            repository.Remove(instance);
        }

        public TEntity GetById<TEntity>(long id)
        {
            IRepository<TEntity> repository = GetRepository<TEntity>();
            return repository.GetById(id);
        }

        public IQueryable<TEntity> FindAll<TEntity>()
        {
            IRepository<TEntity> repository = GetRepository<TEntity>();
            return repository.FindAll();
        }

        public abstract IRepository<T> GetRepository<T>();
    }
}